@extends('admin.common.base-master')

@section('html-head')
        <style>
            body {
                background-color: #d9d9d9;
            }

            .panel {
                box-shadow: 0 0 5px rgba(80, 80, 80, 0.8);
            }

        </style>
@endsection

@section('html-body')
<div style="width: 500px;margin: 100px auto;">
    <form id="login">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">管理员登录</h3>
            </div>
            <div class="panel-body">
                <div class="input-group">
                    <label for="site-name" class="input-group-addon">用户名</label>
                    <input type="text" name="username" id="site-name" class="form-control" required="required"/>
                </div>
                <br>
                <div class="input-group">
                    <label for="user-email" class="input-group-addon">密 &nbsp;&nbsp;码</label>
                    <input type="password" name="password" id="user-email" class="form-control" required="required"/>
                    <input type="hidden" name="remember" id="user-email" value="1" class="form-control" required="required"/>
                </div>
            </div>
            <div class="panel-footer text-center">
                <input type="button" class="btn btn-success form-control" id="login_btn" value="确定"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
   jQuery(function($){
       var doc = document,
               $doc = $(doc);

       jQuery.ajaxSetup({
           case:false,
           headers: {
               'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
           }
       });

       $doc.keydown(function(event){
           if(event.keyCode==13){
               doLogin();
           }
       });

       $doc.on('click','#login_btn',function(){
           doLogin();
       });

       function doLogin(){
           $.ajax({
               type:"post",
               url:'{{route('Api.Auth.SignIn')}}',
               dataType:"json",
               data:$('#login').serialize(),
               success:function(obj){
                   if(obj.level === "success"){
                       window.location.href='{{route('Admin.Index.index')}}';
                   }
               },
               error:function(obj){
                   var datajson = obj.responseJSON;
                   noty({text:datajson.message,type:datajson.level,timeout:800});
               }
           });
       }
   });
</script>
@endsection